//
//  LiveSizeConfig.m
//  ParentsCommunity
//
//  Created by caiyonghao on 16/10/19.
//  Copyright © 2016年 XES. All rights reserved.
//
#import "LiveSizeConfig.h"

static CGFloat kVideoRatioValue = 9 / 16.0f;

@implementation LiveSizeConfig

+ (CGFloat)screenWidth {
    
    return MAX(kCurrentScreenWidth, kCurrentScreenHeight);
}

+ (CGFloat)screenHeight {
    
    return MIN(kCurrentScreenWidth, kCurrentScreenHeight);
}

+ (CGFloat)getLiveVideoAspectRatio {

    return livePPTHeight / (livePPTWidth + liveHeadAreaWidth );

}

+ (CGFloat)getLivePPTAspectRatio {

    return  livePPTWidth / livePPTHeight;
}

+ (CGFloat)getLiveVideoAndPPTWdithRatio {

    return livePPTWidth / (livePPTWidth + liveHeadAreaWidth);
    
}

+ (CGFloat)getLiveVideoAndHeadAreaWidthRatio {

    return liveHeadAreaWidth / (livePPTWidth + liveHeadAreaWidth);

}

+ (CGFloat)getLiveVideoAndChatHeightRatio {

    return (1 -  liveHeadAreaHeight / livePPTHeight);
}

/*!
 * @brief 是否是iphoneX
 */
+ (BOOL)isIphoneX {
   
    CGFloat width = [self screenWidth];
    CGFloat height = [self screenHeight];
    return (ceil(width)  == 812) && (ceil(height) == 375);
}

/*!
 * @brief 水平方向的间距
 */
+ (CGFloat)getHorizontalSpace {
    
    CGFloat width = [self screenWidth];
    CGFloat height = [self screenHeight];
    CGFloat videoHeight = width *kVideoRatioValue;
    
    if (videoHeight > height) {
        
        CGFloat videoWidth = height / kVideoRatioValue;
        return  (width - videoWidth) / 2;
    }
    return  0;
}

/*!
 * @brief 垂直方向间距
 */
+ (CGFloat)getVerticalSpace {
    
    CGFloat width = [self screenWidth];
    CGFloat height = [self screenHeight];
    CGFloat videoHeight = width *kVideoRatioValue;
    
    if (videoHeight < height) {
        
        return (height - videoHeight) / 2;
    }
    return 0;
}

/*!
 * @brief 聊天区的宽度
 */
+ (CGFloat)getChatViewWidth {
   
    CGFloat width = [self screenWidth];
    CGFloat height = [self screenHeight];
    CGFloat videoHeight = width *kVideoRatioValue;
    if (videoHeight > height) {
        
        CGFloat videoWidth = height / kVideoRatioValue;
        return  videoWidth * [self getLiveVideoAndHeadAreaWidthRatio];
    }
    
    return width * [self getLiveVideoAndHeadAreaWidthRatio];
}

/*!
 * @brief 聊天区的高度
 */
+ (CGFloat)getChatViewHeight {
    
    return [self getPPTHeight] * [self getLiveVideoAndChatHeightRatio];
}

/*!
 * @brief PPT区域宽度
 */
+ (CGFloat)getPPTWidth {
    
    CGFloat width = [self screenWidth];
    CGFloat height = [self screenHeight];
    CGFloat videoHeight = width *kVideoRatioValue;
    if (videoHeight > height) {
        
        CGFloat videoWidth = height / kVideoRatioValue;
        return  videoWidth * [self getLiveVideoAndPPTWdithRatio];
    }
    
    return width * [self getLiveVideoAndPPTWdithRatio];
}

/*!
 * @brief PPT区域高度
 */
+ (CGFloat)getPPTHeight {
    
    CGFloat height = [self screenHeight];
    return height - 2 * [self getVerticalSpace];
}


+ (CGFloat)currentScreenWidth
{
    if (!IS_OS_8_OR_LATER)
    {
        switch ([UIApplication sharedApplication].statusBarOrientation)
        {
            case UIInterfaceOrientationPortrait:
            case UIInterfaceOrientationPortraitUpsideDown:
            {
                return [UIScreen mainScreen].bounds.size.width;
            }
                break;
            case UIInterfaceOrientationLandscapeLeft:
            case UIInterfaceOrientationLandscapeRight:
            {
                return [UIScreen mainScreen].bounds.size.height;
            }
                break;
            default:
                break;
        }
    }
    else
    {
        return [UIScreen mainScreen].bounds.size.width;
    }
    return 0;
}

+ (CGFloat)currentScreenHeight
{
    if (!IS_OS_8_OR_LATER)
    {
        switch ([UIApplication sharedApplication].statusBarOrientation)
        {
            case UIInterfaceOrientationPortrait:
            case UIInterfaceOrientationPortraitUpsideDown:
            {
                return [UIScreen mainScreen].bounds.size.height;
            }
                break;
            case UIInterfaceOrientationLandscapeLeft:
            case UIInterfaceOrientationLandscapeRight:
            {
                return [UIScreen mainScreen].bounds.size.width;
            }
                break;
            default:
                break;
        }
    }
    else
    {
        return [UIScreen mainScreen].bounds.size.height;
    }
    return 0;
}



@end
